<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"

          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          :cell-style="cellStyle"
          @cell-click="cellClick"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <el-table-column type="selection" align="center" />
          <Column v-for="(column,index) in tableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
          <el-table-column label="启用状态" align="left" width="180">
            <template slot-scope="scope">
              <span style=" margin-right: 20px">{{ scope.row.statusName }}</span>
              <el-switch
                v-model="scope.row.status"
                active-value="1"
                inactive-value="0"
                @change="editForStatus(scope.row)"
              />
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="120">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click.stop="edit(scope.row)"
              >编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { list, getInfo, editForStatus } from '@/api/system/approvalSettings'
import AddOrUpdate from './addOrUpdate'
import ShowDetail from './showDetail.vue' // 查看页面
export default {
  name: 'Index',
  data() {
    return {
      loading: true,
      pageId: '审批设置', // 页面唯一标识
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      // tableKey: 1,
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'code', label: '审批表单', canOrder: false }
        // { prop: 'rejectName', label: '驳回类型' },
        // { prop: 'remark', label: '备注', canOrder: false }

      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'code', label: '审批表单', type: 'input' },
        { prop: 'status', label: '状态', type: 'select', optionsName: 'statusOptions' }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '页面配置', perm: '' }
      ],
      statusOptions: [ // 选择组件数据源
        { value: undefined, label: '全部' },
        { value: '1', label: '启用' },
        { value: '0', label: '停用' }
      ],
      showKey: // 查看详情的配置（根据配置自动生成查看页面）
        {
          type: 'column_two',
          keys: [
            { type: 'form', name: '审批表单', key: 'code' }, // type: 'form' 表示是普通的表单展示
            { type: 'form', name: '状态', key: 'status' },
            { type: 'form', name: '备注', key: 'remark', length: 'double' },
            {
              type: 'table', name: '审批流程', key: 'details', columns: [ // type: 'table' 表示是表格
                { type: 'column', name: '审批部门', key: 'deptName' }, // type: 'form' 表示是普通的表单展示
                { type: 'column', name: '审批人员', key: 'approvalUserName' }
              ]
            }
          ]
        }
    }
  },
  created() {
    if (this.$store.state.order.contendId) {
      this.edit({ id: this.$store.state.order.contendId })
      this.$store.state.order.contendId = ''
    }
  },
  mounted() {
  },
  methods: {
    cellStyle({ row, column }) {
      if (column.property == 'code') {
        return {
          cursor: 'pointer',
          color: '#387bfc'
        }
      }
    },
    cellClick(row, column, cell) {
      switch (column.property) {
        case 'code':
          this.showDetail(row)
          break
      }
    },
    editForStatus(row) {
      console.log(row)
      editForStatus({ id: row.id, status: row.status }).then(res => {
        this.$message.success('操作成功')
        this.getList()
      })
    },
    showDetail(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: ShowDetail, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            id: row.id
          }// props
        },
        area: ['880px', '700px'],
        title: '查看审批设置', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    getExportData(data) {
      return list(data)
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    refresh2() {
      this.tableData = []
      setTimeout(() => {
        this.getList()
      }, 50)
    },
    getList() {
      list(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.loading = false
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    // add() {
    //   this.$layer.iframe({// 弹框
    //     content: {
    //       content: AddOrUpdate, // 传递的组件对象
    //       parent: this, // 当前的vue对象
    //       data: {}// props
    //     },
    //     area: ['880px', '700px'],
    //     title: '新增生产计划单', // 标题
    //     shadeClose: false // 点击遮罩是否关闭
    //   })
    // },
    edit(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            id: row[this.mainId]
          }// props
        },
        area: ['880px', '700px'],
        title: '编辑审批设置', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
